import React, { lazy, Suspense } from 'react';
import { Spin } from 'antd';

/**
 * 加载组件
 * 在组件加载过程中显示
 */
const LoadingComponent: React.FC = () => (
  <div style={{ 
    display: 'flex', 
    justifyContent: 'center', 
    alignItems: 'center', 
    padding: '50px',
    height: '100%'
  }}>
    <Spin size="large" tip="加载中..." />
  </div>
);

/**
 * 创建懒加载包装器
 * @param importFunc 导入函数
 * @returns 懒加载的组件
 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const createLazyComponent = (importFunc: () => Promise<any>) => {
  const LazyComponent = lazy(importFunc);
  
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return (props: any) => (
    <Suspense fallback={<LoadingComponent />}>
      <LazyComponent {...props} />
    </Suspense>
  );
};

// 登录和公共页面
export const LoginPage = createLazyComponent(() => import('../views/login/Login'));
export const NotFoundPage = createLazyComponent(() => import('../views/NotFound'));

// 新闻相关页面
export const NewsListPage = createLazyComponent(() => import('../views/news/News'));
export const NewsDetailPage = createLazyComponent(() => import('../views/news/Detail'));

// 仪表盘页面
export const HomePage = createLazyComponent(() => import('../views/sandbox/home/Home'));

// 用户管理页面
export const UserListPage = createLazyComponent(() => import('../views/sandbox/user-manage/UserList'));
export const UserProfilePage = createLazyComponent(() => import('../views/sandbox/user-profile/UserProfile'));

// 权限管理页面
export const RoleListPage = createLazyComponent(() => import('../views/sandbox/right-manage/RoleList'));
export const RightListPage = createLazyComponent(() => import('../views/sandbox/right-manage/RightList'));

// 新闻管理页面
export const NewsAddPage = createLazyComponent(() => import('../views/sandbox/news-manage/NewsAdd'));
export const NewsDraftPage = createLazyComponent(() => import('../views/sandbox/news-manage/NewsDraft'));
export const NewsCategoryPage = createLazyComponent(() => import('../views/sandbox/news-manage/NewsCategory'));

// 审核管理页面
export const AuditPage = createLazyComponent(() => import('../views/sandbox/audit-manage/Audit'));
export const AuditListPage = createLazyComponent(() => import('../views/sandbox/audit-manage/AuditList'));

// 发布管理页面
export const UnpublishedPage = createLazyComponent(() => import('../views/sandbox/publish-manage/Unpublished'));
export const PublishedPage = createLazyComponent(() => import('../views/sandbox/publish-manage/Published'));
export const SunsetPage = createLazyComponent(() => import('../views/sandbox/publish-manage/Sunset'));

// 系统设置页面
export const SettingsPage = createLazyComponent(() => import('../views/sandbox/system-settings/Settings')); 